﻿#region " | Copyright 2013 | "
/*
 * Copyright 2013
 * Author : Siriwat Suananpornpanit
 * Attibutes
 */
#endregion

using System;
using System.Reflection;
using System.Web.Mvc;
using Single_SignOn.Models;

namespace Single_SignOn.Attributes
{
    [AttributeUsage(AttributeTargets.Class , AllowMultiple = false, Inherited = true)]
    public class AuthorizeGroupAttibute : ActionMethodSelectorAttribute
    {
       
        public String Group { get; set; }

        public String Access { get; set; }

        public Action _Action { get; set; }

        public Controller _Controller { get; set; }

        public String DataMessage { get; set; }

        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            String[] groupList = Group.Split('|');
            String group = ((UserProfile)(System.Web.HttpContext.Current.Session["UserInfo"])).GroupNo;

            foreach (String grp in groupList)
            {
                if (grp == group)
                {
                    return true;
                }
            }
            
            return false;
        }
    }

}